package subject_set.offer100;

/**
 * @author haomin
 * @date 2022/10/22 18:50
 **/
public class Offer55_Ⅱ {
    class Solution {
        public boolean isBalanced(TreeNode root) {
            if(root == null) return true;
            int l = getDep(root.left);
            int r = getDep(root.right);
            if(Math.abs(l - r) > 1) return false;
            return isBalanced(root.left) && isBalanced(root.right);
        }
        private int getDep(TreeNode cur){
            if(cur == null) return 0;
            return 1 + Math.max(getDep(cur.left), getDep(cur.right));
        }
    }
}